package entity;

import java.awt.image.RescaleOp;
import java.io.Serializable;
public class Result implements Serializable {
    private int code;
    private String message;
    private Object object;

    public Result() {
    }
    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, Object object) {
        this.code = code;
        this.message = message;
        this.object = object;
    }

    /**
     * 返回成功，采用方法重载机制
     * @param object 自定义消息
     * @return 返回[code,message,object]
     */
    public static Result success(Object object){
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),object);
    }
    public static Result success(){
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }

    /**
     * 返回失败，采用方法重载机制
     * @param object 自定义消息
     * @return 返回[code,message,object]
     */
    public static Result failed(Object object){
        return new Result(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMessage(),object);
    }
    public static Result failed(){
        return new Result(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMessage());
    }

    /**
     * 如果不提供 get 方法获取不到数据
     * @return 得到字段
     */
    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getObject() {
        return object;
    }

    /**
     * 如果不提供这个方法，print 输出的是对象地址
     * @return 返回对象中内容的字符串形式
     */
    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}
